//
//  HHWebViewController.m
//  MPWeChatDemo
//
//  Created by HappyMilk 01 on 2017/5/2.
//  Copyright © 2017年 srulos. All rights reserved.
//

#import "HHWebViewController.h"


@interface HHWebViewController ()

@property (nonatomic,strong) UIWebView *webView;
@property(nonatomic,strong)UIActivityIndicatorView *activity;

#define screenW [UIScreen mainScreen].bounds.size.width
#define screenH [UIScreen mainScreen].bounds.size.height

@end

@implementation HHWebViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    
    self.navigationController.navigationBar.tintColor=[UIColor whiteColor];
    NSDictionary *attributes=[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,nil];
    [self.navigationController.navigationBar setTitleTextAttributes:attributes];
    
    self.navigationController.navigationBar.hidden=NO;
    self.webView=[[UIWebView alloc]init];
    self.webView.frame=CGRectMake(0, 64, screenW, screenH-64);
    [self.view addSubview:self.webView];
    
    NSURLRequest *re= [[NSURLRequest alloc]initWithURL:[[NSURL alloc]initWithString:self.url]];
    [self.webView loadRequest:re];
    
    
    UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(8, 28,60, 30)];
    [btn setTitle:@"<返回" forState:0];
    [btn addTarget:self action:@selector(onBtn) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
    [btn setTitleColor:[UIColor blackColor] forState:0];
    
    self.webView.delegate = self;
    
    
    [self showIndicator];
    
    self.view.backgroundColor = [UIColor whiteColor];
   
    
}


-(void)viewDidAppear:(BOOL)animated{
    if([self.url containsString:@"itunes.apple"]){
        [self.activity stopAnimating];
        [self dismissViewControllerAnimated:true completion:nil];
    }
}


-(void)onBtn{
    [self dismissViewControllerAnimated:true completion:nil];
}

-(void)showIndicator{
    self.activity= [[UIActivityIndicatorView alloc]initWithFrame:self.view.bounds];
    
    [self.activity setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleGray];
   
    self.activity.color= [UIColor blackColor];
    
    self.activity.hidesWhenStopped=YES;

    [self.view addSubview:self.activity];
    [self.activity startAnimating];
}



-(void)webViewDidFinishLoad:(UIWebView *)webView{
    [self.activity stopAnimating];
}

@end
